﻿#region Using

using System;

using Common.Base;

using GameCommon.ComponentInterfaces;
using GameCommon.HitBoxes;
using GameCommon.ManagerInterfaces;
using GameCommon.ServiceInterfaces;
using GameCommon.Services;

using Microsoft.Xna.Framework;

using IDrawable = GameCommon.ComponentInterfaces.IDrawable;

#endregion

namespace GameCommon.Components
{
    public abstract class GameComponent : IDrawable, IDisposable
    {
        protected readonly IDrawingService DrawingService;

        private Dimension dimension;

        protected GameComponent(string id)
        {
            this.Id = id;
            this.DrawingService = Service.DrawingService;
            this.Layer = 1;
            this.Opacity = 1;
            this.Offset = new Offset();
        }

        public string Id { get; protected set; }

        public string Command { get; set; }

        public float Opacity { get; set; }

        public int Layer { get; set; }

        public Dimension Dimension
        {
            get
            {
                return this.dimension;
            }

            set
            {
                this.dimension = value;
                var obj = this as IHitable;
                if (obj != null && obj.HitBox != null)
                {
                    obj.HitBox.Dimension = value;
                }
            }
        }

        public Offset Offset { get; set; }

        public Position Position
        {
            get
            {
                return this.Dimension.Position;
            }
        }

        public Size Size
        {
            get
            {
                return this.Dimension.Size;
            }
        }

        public bool Enabled { get; private set; }

        public bool Visible { get; private set; }

        public virtual void Dispose()
        {
        }

        public abstract void Draw(IDrawingManager manager, GameTime gameTime);

        public void Disable()
        {
            this.Enabled = false;
        }

        public void Enable()
        {
            this.Enabled = true;
        }

        public void Hide()
        {
            this.Visible = false;
        }

        public void Show()
        {
            this.Visible = true;
        }

        public virtual void Settle()
        {
        }
    }
}